package com.me.aop;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.me.aop.config.AopConfig;
import com.me.aop.dao.IndexDao;
import com.me.aop.dao.IndexDaoImpl;
import com.me.aop.dao.IntroductionDao;
import com.me.aop.pojo.T1;
import com.me.aop.pojo.T2;

/**
 * AOP学习: AOP 测试类
 *
 * @author ME
 * @date   2019/11/13
 */
public class TestAop {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AopConfig.class);
        IndexDao dao = (IndexDao) context.getBean("indexDao");
        /*
         * @EnableAspectJAutoProxy 默认使用 JDK动态代理, 此时代理类继承 java.lang.reflect.Proxy, 实现 Dao, 类型不再是 IndexDaoImpl.
         *      打印 false
         * @EnableAspectJAutoProxy(proxyTargetClass = true), 强制使用 CGlib, 代理类继承了 IndexDaoImpl
         *      打印 true
         */
        System.out.println(dao instanceof IndexDaoImpl);

        System.out.println("\n---------------------------------------------------------------");
        dao.query();

        System.out.println("\n---------------------------------------------------------------");
        dao.query(1);

        System.out.println("\n---------------------------------------------------------------");
        dao.query("hello");

        System.out.println("\n---------------------------------------------------------------");
        dao.query(23, "asgahda");

        System.out.println("\n---------------------------------------------------------------");
        T1 t1 = new T1();
        dao.query(t1);

        System.out.println("\n---------------------------------------------------------------");
        T2 t2 = new T2();
        dao.query(t2);

        System.out.println("\n---------------------------------------------------------------");
        System.out.println("introduction: ");
        IntroductionDao dao1 = (IntroductionDao) context.getBean("testDao");
        dao1 = context.getBean("testDao", IntroductionDao.class);
        dao1.testIntroductionMethod();
    }
}
